home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / windows / comman10.zip / COMMAN.WAS
Text File  |  1992-10-14  |  7KB  |  148 lines

  1. ; ComMan.WAS v 1.00  COM port monitor
  2. ;****************************************************************************
  3. ;*                                                                          *
  4. ;* COMMAN.WAS                                                               *
  5. ;* Copyright (C) 1992 Datastorm Technologies, Inc.                          *
  6. ;* All rights reserved.                                                     *
  7. ;*                                                                          *
  8. ;* Purpose:  Monitors COM port activity, displaying number of characters in *
  9. ;*           the receive and transmit buffers, state of CD (high or low),   *
  10. ;*           and state of flow control (clear, XOFF, or CTS).               *
  11. ;*                                                                          *
  12. ;* This ASPECT SCRIPT is intended only as a sample of ASPECT programming.   *
  13. ;* DATASTORM makes no warranty of any kind, express or implied, including   *
  14. ;* without limitation, any warranties of merchantability and/or fitness     *
  15. ;* for a particular purpose.  Use of this program is at your own risk.      *
  16. ;*                                                                          *
  17. ;* Author:  Chuck Spohr                                                     *
  18. ;*                                                                          *
  19. ;****************************************************************************
  20.  
  21. ;****************************************************************************
  22. ;*   GLOBAL VARIABLES                                                       *
  23. ;****************************************************************************
  24.  
  25. integer RXi, OldRxi=-1, TXi, OldTxi=-1, CDi, OldCDi=-1, FLi, OldFLi=-1, Change
  26. string RX="", TX="", CD="Low", FL="Clear"
  27.  
  28. ;****************************************************************************
  29. ;*                                                                          *
  30. ;* MAIN                                                                     *
  31. ;* The Main procedure first records the window ID's, then enters a loop to  *
  32. ;* monitor the status of the current COM port.                              *
  33. ;*                                                                          *
  34. ;* Calls:  Dlg, CheckStat,                                                  *
  35. ;* Modifies globals:  none                                                  *
  36. ;*                                                                          *
  37. ;****************************************************************************
  38.  
  39. proc Main
  40.    integer ComManWin, LastWin, CurWin
  41.    
  42.    CurWin=$ACTIVEWIN                       ; Record PW window ID
  43.    Dlg()                                   ; Display dialogbox
  44.    ComManWin=$ACTIVEWIN                    ; Record script window ID
  45.    activatewin CurWin                      ; Make script window active
  46.  
  47.    while !$DIALOG                          ; Run until dialogbox is closed
  48.       LastWin=CurWin                       ; Keep script in background
  49.       if (CurWin=$ActiveWin) == ComManWin
  50.          activatewin LastWin
  51.       endif
  52.  
  53.       CheckStat()
  54.  
  55.       if Change
  56.          updatedlg 64
  57.          Change=0
  58.       endif
  59.    endwhile
  60. endproc
  61.  
  62. ;****************************************************************************
  63. ;*                                                                          *
  64. ;* CHECKSTAT                                                                *
  65. ;* The CheckStat checks $RXCOUNT, $TXCOUNT, $CARRIER and $FLOWSTATE.  If a  *
  66. ;* change is sensed, the old value is stored, and the new value is          *
  67. ;* retrieved.                                                               *
  68. ;*                                                                          *
  69. ;* Calls: none                                                              *
  70. ;* Modifies globals: RXi, OldRxi, TXi, OldTxi, CDi, OldCDi, FLi, OldFLi     *
  71. ;*                   Change, RX, TX, CD, FL                                 *
  72. ;*                                                                          *
  73. ;****************************************************************************
  74.  
  75. proc CheckStat
  76.    RXi=$RXCOUNT          ; Get number of characters in receive data buffer
  77.    if RXi!=OldRXi        ; Is it different than the last check?
  78.       Change=1           ; If so, flag a change
  79.       OldRXi=RXi         ;    store the value
  80.       if RXi             ;    and set the string variable
  81.          itoa RXi RX
  82.       else
  83.          RX=""           ; If there are no characters, clear the string
  84.       endif
  85.    endif
  86.  
  87.    TXi=$TXCOUNT          ; Get number of characters in transmit buffer
  88.    if TXi!=OldTXi
  89.       Change=1
  90.       OldTXi=TXi
  91.       if TXi
  92.          itoa TXi TX
  93.       else
  94.          TX=""
  95.       endif
  96.    endif
  97.  
  98.    CDi=$CARRIER          ; Get the state of Carrier Detect
  99.    if CDi!=OldCDi
  100.       Change=1
  101.       OldCDi=CDi
  102.       if CDi
  103.          CD="High"
  104.       else
  105.          CD="Low"
  106.       endif
  107.    endif
  108.  
  109.    FLi=$FLOWSTATE        ; Get the state of flow control
  110.    if FLi!=OldFLi
  111.       Change=1
  112.       OldFLi=FLi
  113.       if FLi             ; If flow is paused, determine if it was due to XOFF
  114.          if strcmp $LASTMSG "XOFF received"
  115.             FL="XOFF"
  116.          else
  117.             FL="CTS"     ; If not XOFF, then it must be CTS
  118.          endif
  119.          statmsg ""      ; Clear statline and $LASTMSG
  120.       else
  121.          FL="Clear"      ; If flow is not paused, set string to "Clear"
  122.       endif
  123.    endif
  124. endproc
  125.  
  126. ;****************************************************************************
  127. ;*                                                                          *
  128. ;* DLG                                                                      *
  129. ;* The Dlg procedure displays the main dialogbox                            *
  130. ;*                                                                          *
  131. ;* Calls: none                                                              *
  132. ;* Modifies globals: none                                                   *
  133. ;*                                                                          *
  134. ;****************************************************************************
  135.  
  136. proc Dlg
  137.    dialogbox 250 0 45 33 6 "ComMan"
  138.       text  3 0 16 8 right "RX:"
  139.       text  3 8 16 8 right "TX:"
  140.       text  3 16 16 8 right "CD:"
  141.       text  3 24 17 8 right "Flow:"
  142.       vtext 21 0 24 9 left RX
  143.       vtext 21 8 24 9 left TX
  144.       vtext 21 16 24 9 left CD
  145.       vtext 21 24 24 9 left FL
  146.    enddialog
  147. endproc
  148.